from skimage import io,util,color,measure
import matplotlib.pyplot as plt
import cv2
import os
import Image
import numpy as np

def test_rgb_2_yuv():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/decsai/CM512/inf/tahoe.ppm'
    img_arr = io.imread(img_path)
    print img_arr.shape

    img_arr_c = cv2.cvtColor(img_arr,cv2.COLOR_RGB2YUV)
    print img_arr_c.shape
    plt.subplot(1,2,1)
    io.imshow(img_arr)
    plt.subplot(1,2,2)
    io.imshow(img_arr_c[:,:,:])
    io.show()

    img_arr = cv2.cvtColor(img_arr_c,cv2.COLOR_YUV2RGB)
    io.imshow(img_arr)
    io.show()

def test_gray_2_rgb():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/decsai/GM512/inf/peppers.pgm'
    img_arr = io.imread(img_path)
    img_arr_rgb = color.gray2rgb(img_arr)
    print img_arr_rgb[0,0,:]
    io.imshow(img_arr_rgb)
    io.show()

def show_flags_in_cv2():
    flags = [i for i in dir(cv2) if i.startswith('INTER_')]
    print flags

def test_upscale():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/SRCNNset/Test/Set5/butterfly_GT.bmp'
    img_arr = io.imread(img_path)
    img_ar_resized = cv2.resize(img_arr,None,fx=1/2., fy=1/2., interpolation = cv2.INTER_CUBIC)
    img_ar_resized = cv2.resize(img_ar_resized,None,fx=2., fy=2., interpolation = cv2.INTER_CUBIC)
    print measure.compare_psnr(img_arr,img_ar_resized)
    plt.subplot(1,2,1)
    io.imshow(img_arr)
    plt.subplot(1,2,2)
    io.imshow(img_ar_resized)
    io.show()

def test_os_walk():
    folder = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/SRCNNset/Test'
    for dirpath,dirname,filname in os.walk(folder):
        print dirpath
        print dirname
        print filname

def show_nb_chnnels():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/SRCNNset/Test/Set14/man.bmp'
    img_arr = io.imread(img_path)
    print img_arr.shape

def test_skimage_crop():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/SRCNNset/Test/Set14/man.bmp'
    img_arr = io.imread(img_path)
    img_arr_cropped = util.crop(img_arr,crop_width=((512,90),(512,90)))
    plt.subplot(1,2,1)
    io.imshow(img_arr)
    plt.subplot(1,2,2)
    io.imshow(img_arr_cropped)
    io.show()

def test_Image():
    img_path = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/SRCNNset/Test/Set14/man.bmp'
    img_arr_ = io.imread(img_path)
    img_obj = Image.open(img_path)
    img_arr = np.reshape(np.asarray(list(img_obj.getdata()),dtype=np.uint8),(512,512,3))
    print img_arr.dtype
    print measure.compare_psnr(img_arr_,img_arr)
    plt.subplot(1,2,1)
    io.imshow(img_arr_)
    plt.subplot(1,2,2)
    io.imshow(img_arr)
    io.show()

def test_stride():
    for i in range(1,10,3):
        print i

if __name__ == '__main__':
    test_stride()